import { SixtyCopyBuildBase } from "./SixtyCopyBuildBase";
import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Cache } from "../../../cache/Cache";
import { CopyConfig } from "../../../resource/CopyConfig";
import { MsgManager } from "../../../manager/MsgManager";
import { Language } from "../../../../../extend/language/Language";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { T60DefenseCopyConfig } from "../../../../../Message/Db/Tables/T60DefenseCopyConfig";
import { BossConfig } from "../../../resource/BossConfig";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
type int = number;
//class SixtyDefenceBuilding
    
    export  class SixtyDefenceBuilding /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            this._base = new SixtyCopyBuildBase();
            this.addChild(this._base);
            this._levelupBtn = ObjCreate.createGButton("", 7, 68, 24, 22, this, "LevelUpBtn");
            this._levelupBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._callBtn = ObjCreate.createGLoadedButton(ResFileConst.SixtyDefenceZhao, 35, 68, 24, 22, this);
            this._callBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=false;
            if (!this._config) 
            {
                return;
            }
            var loc1=Cache.instance.copy.sixtyDefenceCopyInfo ? Cache.instance.copy.sixtyDefenceCopyInfo.score : 0;
            var loc3=arg1.target;
            switch (loc3) 
            {
                case this._levelupBtn:
                {
                    loc2 = CopyConfig.instance.isHighestLevelBoss(this._config);
                    if (loc1 < this._config.upgradeSocore) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(60386));
                    }
                    else if (loc2) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(60374));
                    }
                    else 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.Copy60DefenceUpgrade, this._config.type));
                    }
                    break;
                }
                case this._callBtn:
                {
                    if (this._config.level != 0) 
                    {
                        if (loc1 < this._config.useSocore) 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(60386));
                        }
                        else 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.Copy60DefenceUse, this._config.type));
                        }
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(60373));
                    }
                    break;
                }
            }
            return;
        }

        public set copyCode(arg1: int)
        {
            this._copyCode = arg1;
            this.updateBuildInfo();
            return;
        }

        public set bossType(arg1: int)
        {
            this._bossType = arg1;
            this.updateBuildInfo();
            return;
        }

        public set bossLevel(arg1: int)
        {
            if (this._bossLevel != arg1) 
            {
                if (arg1 == this._bossLevel + 1) 
                {
                    this._levelUp = true;
                }
                this._bossLevel = arg1;
                this.updateBuildInfo();
            }
            return;
        }

        public set bossNum(arg1: int)
        {
            if (this._bossNum != arg1) 
            {
                this._bossNum = arg1;
                this.updateBuildInfo();
            }
            return;
        }

        /* internal  */updateBuildInfo(): void
        {
            var loc1=false;
            var loc2=0;
            this._config = CopyConfig.instance.get60DefenceConfig(this._copyCode, this._bossType, this._bossLevel);
            if (this._config) 
            {
                if (this._levelUp) 
                {
                    this._levelUp = false;
                    if (this._config.broadcast != "") 
                    {
                        MsgManager.showTaskTarget(this._config.broadcast);
                    }
                }
                this._base.updateInfo(this._config, this._bossNum);
                this._levelupBtn.toolTipData = HTMLUtil.addColor(this.getLevelUpBtnTooltip(this._config), "#FFFFFF");
                this._callBtn.toolTipData = HTMLUtil.addColor(this.getCallBtnTooltip(this._config), "#FFFFFF");
                loc1 = CopyConfig.instance.isHighestLevelBoss(this._config);
                loc2 = Cache.instance.copy.sixtyDefenceCopyInfo ? Cache.instance.copy.sixtyDefenceCopyInfo.score : 0;
                if (this._config.level == 0 || loc2 < this._config.useSocore) 
                {
                    this._callBtn.filters = [FilterConst.colorFilter2];
                    this._callEnable = false;
                }
                else 
                {
                    this._callBtn.filters = [];
                    this._callEnable = true;
                }
                if (loc2 < this._config.upgradeSocore || loc1) 
                {
                    this._levelupBtn.filters = [FilterConst.colorFilter2];
                    this._levelupEnable = false;
                }
                else 
                {
                    this._levelupBtn.filters = [];
                    this._levelupEnable = true;
                }
            }
            return;
        }

        /* internal  */getLevelUpBtnTooltip(arg1: T60DefenseCopyConfig): string
        {
            if (arg1.level >= 10) 
            {
                return Language.getString(60374);
            }
            var loc1="";
            var loc2=BossConfig.instance.getInfoByCode(arg1.bossCode);
            if (loc2) 
            {
                loc1 = loc1 + (Language.getStringByParam(60377, loc2.boss.name) + "\n");
            }
            var loc3=Cache.instance.copy.sixtyDefenceCopyInfo ? Cache.instance.copy.sixtyDefenceCopyInfo.score : 0;
            loc1 = loc1 + (Language.getStringByParam(60378, arg1.upgradeSocore) + "\n");
            loc1 = loc1 + (Language.getStringByParam(60379, loc3) + "\n");
            if (loc3 >= arg1.upgradeSocore) 
            {
                loc1 = loc1 + (HTMLUtil.addColor(Language.getString(60380), "#FFFF00") + "\n");
            }
            else 
            {
                loc1 = loc1 + (HTMLUtil.addColor(Language.getString(60383), "#FF0000") + "\n");
            }
            return loc1;
        }

        /* internal  */getCallBtnTooltip(arg1: T60DefenseCopyConfig): string
        {
            var loc1="";
            var loc2=BossConfig.instance.getInfoByCode(arg1.bossCode);
            if (loc2) 
            {
                loc1 = loc1 + (Language.getStringByParam(60381, loc2.boss.name) + "\n");
            }
            var loc3=Cache.instance.copy.sixtyDefenceCopyInfo ? Cache.instance.copy.sixtyDefenceCopyInfo.score : 0;
            loc1 = loc1 + (Language.getStringByParam(60378, arg1.useSocore) + "\n");
            loc1 = loc1 + (Language.getStringByParam(60379, loc3) + "\n");
            if (loc3 >= arg1.useSocore) 
            {
                loc1 = loc1 + (HTMLUtil.addColor(Language.getString(60382), "#FFFF00") + "\n");
            }
            else 
            {
                loc1 = loc1 + (HTMLUtil.addColor(Language.getString(60383), "#FF0000") + "\n");
            }
            return loc1;
        }

        /* internal */ /* var */_copyCode: int;

        /* internal */ /* var */_bossType: int;

        /* internal */ /* var */_bossLevel: int;

        /* internal */ /* var */_bossNum: int;

        /* internal */ /* var */_config: T60DefenseCopyConfig;

        /* internal */ /* var */_base: SixtyCopyBuildBase;

        /* internal */ /* var */_levelupBtn: GButton;

        /* internal */ /* var */_callBtn: GLoadedButton;

        /* internal */ /* var */_callEnable: Boolean;

        /* internal */ /* var */_levelupEnable: Boolean;

        /* internal */ /* var */_levelUp: Boolean=false;
    }
